package com.qf.index.gcrdo;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.db.ds.DSFactory;
import com.alibaba.fastjson.JSONArray;
import lombok.SneakyThrows;

import java.util.List;

/**
 * @Author: 葛成瑞
 * @Date: 2025/5/16 17:22
 */
public class SpTable {
    @SneakyThrows
    public static void main(String[] args) {
        // 进行拆分表格如果表 word_and_code_set_map_new  的code_set 字段是多个拆成多个

        Db use = Db.use(DSFactory.get("localdb"));
        String table = "word_and_code_set_map_new";
        List<Entity> query = use.query("select * from " + table + " where code_set like '%,%'");
        for (Entity entity : query) {
            String codeSet = entity.getStr("code_set");
            String word = entity.getStr("word");
            if (codeSet.contains(",")) {
                JSONArray objects = JSONArray.parseArray(codeSet);
                for (Object object : objects) {
                    Integer integer = (Integer) object;
                    Entity ins = new Entity();
                    ins.set("word", word);
                    ins.setTableName(table);
                    ins.set("code_set", "[" + integer + "]");
                    try {
                        use.insert(ins);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
                use.del(entity);
            }
        }

    }
}
